#include "rclcpp/rclcpp.hpp"
#include "data_reflow_interfaces/msg/get_event.hpp"

namespace data_reflow
{
    class CollisionEventPublisher : public rclcpp::Node
    {
    public:
        CollisionEventPublisher() : Node("collision_event_publisher")
        {
            // 创建发布者
            event_pub_ = this->create_publisher<data_reflow_interfaces::msg::GetEvent>(
                "event_topic", 10);

            // 启动时发布一次碰撞事件
            publish_collision_event();
        }

    private:
        void publish_collision_event()
        {
            auto msg = data_reflow_interfaces::msg::GetEvent();
            msg.event_type = "collision";
            msg.stamp = this->get_clock()->now();
            msg.description = "模拟正面碰撞事件 - 启动时自动发布";

            event_pub_->publish(msg);
            RCLCPP_INFO(this->get_logger(), "已发布碰撞事件，时间戳：%d.%09u",
                        msg.stamp.sec, msg.stamp.nanosec);
        }

        rclcpp::Publisher<data_reflow_interfaces::msg::GetEvent>::SharedPtr event_pub_;
    };
}  // namespace data_reflow

int main(int argc, char *argv[])
{
    rclcpp::init(argc, argv);
    auto node = std::make_shared<data_reflow::CollisionEventPublisher>();
    rclcpp::spin(node);  // 保持节点运行
    rclcpp::shutdown();
    return 0;
}